//
//  DemoTableView109SettingViewController.m
//  DemoTableView109Setting
//
//  Created by yang on 10-10-8.
//  Copyright 2010 www.1000phone.com. All rights reserved.
//

#import "DemoTableView109SettingViewController.h"

@implementation DemoTableView109SettingViewController

@synthesize myTableView;
@synthesize settingArray;

/*
// The designated initializer. Override to perform setup that is required before the view is loaded.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
*/

/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
    [super viewDidLoad];
	
	NSDictionary *d1 = [NSDictionary dictionaryWithObjectsAndKeys:
						@"启动翻页声音", @"title",
						@"", @"subTitle",
						@"BOOL", @"type",
						nil];
	NSDictionary *d2 = [NSDictionary dictionaryWithObjectsAndKeys:
						@"允许横屏", @"title",
						@"", @"subTitle",
						@"BOOL", @"type",
						nil];
	NSDictionary *d3 = [NSDictionary dictionaryWithObjectsAndKeys:
						@"同步时间", @"title",
						@"2011-11-09", @"subTitle",
						@"CHECK", @"type",
						nil];
	NSArray *array1 = [NSArray arrayWithObjects:
						d1, d2, d3, nil];
	
	NSDictionary *d4 = [NSDictionary dictionaryWithObjectsAndKeys:
						@"主题", @"title",
						@"经典主题", @"subTitle",
						@"CHECK", @"type",
						nil];
	NSDictionary *d5 = [NSDictionary dictionaryWithObjectsAndKeys:
						@"晃动切换主题", @"title",
						@"", @"subTitle",
						@"BOOL", @"type",
						nil];
	NSArray *array2 = [NSArray arrayWithObjects:
						d4, d5, nil];
	
	
	NSArray *allArray = [NSArray arrayWithObjects:
				[NSDictionary dictionaryWithObjectsAndKeys:
						@"通用设置", @"title",
						array1, @"value",nil],
				[NSDictionary dictionaryWithObjectsAndKeys:
						@"主题", @"title",
						array2, @"value", nil],
						 nil
						 ];
	self.settingArray = allArray;
	
}


/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
	self.settingArray = nil;
	self.myTableView = nil;
    [super dealloc];
}

- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
	return [self.settingArray count];
}
- (NSString *) tableView:(UITableView *)tableView
	titleForHeaderInSection:(NSInteger)section
{
	NSDictionary *dic = [self.settingArray objectAtIndex:section];
	return (NSString *)[dic objectForKey:@"title"];
	
	if (section == 0)
		return @"通用设置";
	else 
		return @"主题";
}
- (NSInteger) tableView:(UITableView *)tableView
	numberOfRowsInSection:(NSInteger)section
{
	NSDictionary *dic = [self.settingArray objectAtIndex:section];
	NSArray *array = [dic objectForKey:@"value"];
	return [array count];
	
	if (section == 0) {
		return 3;
	} else {
		return 2;
	}
}
- (UITableViewCell *) tableView:(UITableView *)tableView
		cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
	int section = [indexPath section];
	int row = [indexPath row];

	NSDictionary *dic = [self.settingArray objectAtIndex:section];
	NSArray *array = [dic objectForKey:@"value"];
	NSDictionary *dicItem = [array objectAtIndex:row];
	
	NSString *title = [dicItem objectForKey:@"title"];
	NSString *subTitle = [dicItem objectForKey:@"subTitle"];
	NSString *type = [dicItem objectForKey:@"type"];
	NSString *name = @"BoolCell";

	if ([type isEqualToString:@"BOOL"]) {
		name = @"BoolCell";
	} else {
		name = @"CheckCell";
	}
	UITableViewCell *cell = [tableView 
					dequeueReusableCellWithIdentifier:name];
	if ( cell == nil) {
		cell = [[[NSBundle mainBundle] 
				 loadNibNamed:name
				 owner:self
				 options:nil] lastObject];
	}
	UILabel *titleLabe = (UILabel *)[cell viewWithTag:101];
	UILabel *subTitleLabel = (UILabel *)[cell viewWithTag:102];
	if (title) {
		titleLabe.text = title;
	}
	if (subTitleLabel) {
		subTitleLabel.text = subTitle;
		cell.accessoryType =
		UITableViewCellAccessoryDisclosureIndicator;
		cell.selectionStyle = UITableViewCellSelectionStyleBlue;
	} else {
		cell.selectionStyle = UITableViewCellSelectionStyleNone;
	}
	return cell;
	
	
#if 0
	/***------*/
	NSString *name = @"BoolCell";
	int section = [indexPath section];
	int row = [indexPath row];
	if (section == 0 && row == 2)
		name = @"CheckCell";
	if (section == 1 && row == 0)
		name = @"CheckCell";
	UITableViewCell *cell = [tableView 
				dequeueReusableCellWithIdentifier:name];
	if ( cell == nil) {
		cell = [[[NSBundle mainBundle] 
					loadNibNamed:name
					owner:self
					options:nil] lastObject];
	}
	UILabel *title = (UILabel *)[cell viewWithTag:101];
	UILabel *subTitle = (UILabel *)[cell viewWithTag:102];
	if (title) {
		title.text = @"title";
	}
	if (subTitle) {
		subTitle.text = @"sub Title";
		cell.accessoryType =
			UITableViewCellAccessoryDisclosureIndicator;
		cell.selectionStyle = UITableViewCellSelectionStyleBlue;
	} else {
		cell.selectionStyle = UITableViewCellSelectionStyleNone;
	}
	return cell;
#endif
}

@end
